package com.expense.app.admin.controller;

import com.expense.app.admin.model.params.job.JobImportParam;
import com.expense.app.admin.annotation.IgnoreAuth;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import javax.validation.constraints.Min;
import com.expense.common.util.Result;
import com.expense.app.admin.services.SchoolServ;
import com.expense.app.admin.model.params.school.SchoolParam;
import com.expense.app.admin.model.params.school.SchoolListParam;

/*
*
* gen controller 2019-11-14
*/
@Validated
@RestController
@RequestMapping("/school")
public class SchoolCtrl {

    @Autowired
    SchoolServ schoolServ;

    @PostMapping("/import")
    public Result importExcel(@RequestBody JobImportParam param) {
        return Result.success(schoolServ.importExcel(param));
    }

    @IgnoreAuth
    @GetMapping("/web/list")
    public Result findWebList(@Validated SchoolListParam param){
        return Result.success(schoolServ.findList(param));
    }

    @GetMapping("")
    public Result findList(@Validated SchoolListParam param) {
        return Result.success(schoolServ.findList(param));
    }

    @GetMapping(value = "/{id}")
    public Result findDetail (@PathVariable @Min(1) Long id) {
        return Result.success(schoolServ.findDetail(id));
    }

    @PostMapping(value = "")
    public Result saveOne(@Validated @RequestBody SchoolParam param) {
        return Result.success(schoolServ.saveOne(param));
    }

    @PutMapping(value = "")
    public Result update(@Validated @RequestBody SchoolParam param) {
        return Result.success(schoolServ.saveOne(param));
    }

    @DeleteMapping(value = "/{id}")
    public Result deleteOne(@PathVariable @Min(1) Long id) {
        return Result.success(schoolServ.deleteOne(id));
    }
}
